package com.woniuxy.automotivemanagementsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.automotivemanagementsystem.entity.Role;
import com.woniuxy.automotivemanagementsystem.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据用户编号查询角色信息
     * @param uid
     * @return
     */
    @Select("select * from user_role ur join role r on ur.rid = r.rid where ur.uid = #{uid}")
    List<Role> findRoleByUserId(@Param("uid") Integer uid);

    @Select("select * from user_role ur join user u on ur.uid = u.uid where ur.rid = #{rid}")
    List<User> selectUserByRid(@Param("rid") Integer rid);
    @Select("select * from role_menu rm join role r on rm.rid = r.rid where rm.mid = #{mid}")
    List<Role> selectRolesByMid(Integer mid);

    /*
    * 注册用户后给用户分配角色
    * */
    @Insert("insert into user_role(uid,rid) values(#{uid},#{rid})")
    void insertUserRole(@Param("uid") Integer uid,@Param("rid") int i);
}
